package huaban;


import org.apache.commons.io.FileUtils;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;

public class Download implements Runnable {
    private static final Logger logger = LoggerFactory.getLogger(Download.class);
    private String url="http://img.hb.aicdn.com/";

    private String key;

    @Override
    public void run() {
        try {
            Connection.Response response = Jsoup.connect(url+key).ignoreContentType(true).execute();
            FileUtils.writeByteArrayToFile(new File("/home/abely/Pictures/huaban5/"+key + System.currentTimeMillis()), response.bodyAsBytes());
        } catch (IOException e) {
            logger.error("download error, the url is {}", url);
        }
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }
}
